package com.ruoyi.report.controller;

import java.util.List;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.report.domain.TPopularizeArticle;
import com.ruoyi.report.service.ITPopularizeArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 文章分类Controller
 *
 * @author administrator
 * @date 2025-02-12
 */
@RestController
@RequestMapping("/project/article")
public class TPopularizeArticleController extends BaseController {
    private String prefix = "project/article";

    @Autowired
    private ITPopularizeArticleService tPopularizeArticleService;

    @GetMapping()
    public String article() {
        return prefix + "/article";
    }

    /**
     * 查询文章分类列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TPopularizeArticle tPopularizeArticle) {
        startPage();
        List<TPopularizeArticle> list = tPopularizeArticleService.selectTPopularizeArticleList(tPopularizeArticle);
        return getDataTable(list);
    }

    /**
     * 导出文章分类列表
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody TPopularizeArticle tPopularizeArticle) {
        List<TPopularizeArticle> list = tPopularizeArticleService.selectTPopularizeArticleList(tPopularizeArticle);
        ExcelUtil<TPopularizeArticle> util = new ExcelUtil<TPopularizeArticle>(TPopularizeArticle.class);
        return util.exportExcel(list, "article");
    }

    /**
     * 新增文章分类
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存文章分类
     */
    @PostMapping("/add")
    public AjaxResult addSave(@RequestBody TPopularizeArticle tPopularizeArticle) {
        return toAjax(tPopularizeArticleService.insertTPopularizeArticle(tPopularizeArticle));
    }

    /**
     * 修改文章分类
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        TPopularizeArticle tPopularizeArticle = tPopularizeArticleService.selectTPopularizeArticleById(id);
        mmap.put("tPopularizeArticle", tPopularizeArticle);
        return prefix + "/edit";
    }

    /**
     * 修改保存文章分类
     */
    @PostMapping("/edit")
    public AjaxResult editSave(@RequestBody TPopularizeArticle tPopularizeArticle) {
        return toAjax(tPopularizeArticleService.updateTPopularizeArticle(tPopularizeArticle));
    }

    /**
     * 删除文章分类
     */
    @GetMapping("/remove")
    public AjaxResult remove( Long id) {
        return toAjax(tPopularizeArticleService.deleteTPopularizeArticleById(id));
    }
}
